#ifndef GAMEOBJECT2D_H
#define GAMEOBJECT2D_H
#include "GameObject.h"
class GameObject2D : public GameObject
{
protected:
	Vector2f position;
	Vector2f move;
	float rotation;
	Sprite* sprite;
	SpriteAnimInstance* animInst;
	int frame;
	bool useAnim;
	bool destroyed;
	bool removed;
public:
	int hp;
	GameObject2D()
	{
		animInst = new SpriteAnimInstance();
		rotation = 0.0f;
		frame = 0;
		useAnim = false;
		destroyed = false;
		removed = false;
		hp = 1;
	}
	virtual ~GameObject2D()
	{
		SafeDelete(animInst);
	}
	virtual void Init();
	virtual void Render();
	virtual void Update(float timeDelta);
	virtual void Release();
	virtual void Destroy()
	{
		destroyed = true;
	}
	void SetAnim(SpriteAnim* anim)
	{
		this->animInst->time = 0;
		this->animInst->currentFrame = 0;
		this->animInst->anim = anim;
	}
	void EnableAnim(bool enable)
	{
		useAnim = enable;
	}
	b2Transform GetBox2DTransform()
	{
		return b2Transform(b2Vec2(position.x, position.y), b2Rot(rotation));
	}
	virtual BoundGroup* GetBodyRegion()
	{
		return sprite->GetFrame((useAnim == true) ? animInst->currentFrame : frame)->boundGroups[BoundGroup::BG_TYPE_BODY];
	}
	virtual BoundGroup* GetDamageRegion()
	{
		return sprite->GetFrame((useAnim == true) ? animInst->currentFrame : frame)->boundGroups[BoundGroup::BG_TYPE_WEAPON];
	}
	virtual bool CollisionCheckBodyRegion(BoundGroup* bg, b2Transform* transform)
	{
		return sprite->GetFrame((useAnim == true) ? animInst->currentFrame : frame)->boundGroups[BoundGroup::BG_TYPE_BODY]->IsIntersectedWith(bg, &GetBox2DTransform(), transform);
	}
	virtual bool CollisionCheckWeaponRegion(BoundGroup* bg, b2Transform* transform)
	{
		return sprite->GetFrame((useAnim == true) ? animInst->currentFrame : frame)->boundGroups[BoundGroup::BG_TYPE_WEAPON]->IsIntersectedWith(bg, &GetBox2DTransform(), transform);
	}
	void SetPosition(float x, float y)
	{
		position.x = x;
		position.y = y;
	}
	void SetSprite(Sprite *s)
	{
		sprite = s;
	}
	bool IsRemoved()
	{
		return removed;
	}
};
#endif